package traveler.tools;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.OverlayItem;

public class OverlayItems extends com.google.android.maps.ItemizedOverlay<OverlayItem>
{
	private ArrayList<OverlayItem> _overlays = new ArrayList<OverlayItem>();
	private Context _context;
	
	public OverlayItems(Drawable defaultMarker, Context context)
	{
	  this(defaultMarker);
	  _context = context;
	}
	
	public OverlayItems(Drawable defaultMarker)
	{
		super(boundCenterBottom(defaultMarker));
	}

	@Override
	protected OverlayItem createItem(int i)
	{
		return _overlays.get(i);
	}

	@Override
	public int size()
	{
		return _overlays.size();
	}
	
	public void addOverlay(OverlayItem overlay)
	{
		_overlays.add(overlay);
	    populate();
	}
	
	@Override
	protected boolean onTap(int index)
	{
	  OverlayItem item = _overlays.get(index);
	  AlertDialog.Builder dialog = new AlertDialog.Builder(_context);
	  dialog.setTitle(item.getTitle());
	  dialog.setMessage(item.getSnippet());
	  dialog.show();
	  return true;
	}
}
